using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
using System.Text;
using System.Xml;
using CS6238Project2.Banking.Communication;
using CS6238Project2.Banking.Commerce;
using CS6238Project2.Banking.Tools;
using CS6238Project2.Banking.Entity;
using CS6238Project2;
using CS6238Project2.GUI;
using System.IO;
using System.Xml.Serialization;




namespace CS6238Project2.GUI
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            ProfileBox profileBox = new ProfileBox();
            profileBox.ShowDialog();

            if (profileBox.Profile == "User")
            {
                UserDisplay display;
                Initialization initializatonWindow = new Initialization();
                initializatonWindow.ShowDialog();
                initializatonWindow.NewName(false);
                if (initializatonWindow.Instance != null)
                {
                    //Okay so this means it exists, let's instantiate it..
                    display = new UserDisplay();
                    display.User = (User)initializatonWindow.Instance;
                }
                else
                {
                    Initialization initial = new Initialization();
                    initial.NewName(true);
                    initial.ShowDialog();
                    display = new UserDisplay();
                    display.User.Name = initial.InstanceName;
                    display.Text = initial.InstanceName;
                }

                Application.Run(display);
            }
            else if (profileBox.Profile == "Bank")
            {
                BankDisplay display;
                Initialization initializatonWindow = new Initialization();
                initializatonWindow.ShowDialog();
                initializatonWindow.NewName(false);
                if (initializatonWindow.Instance != null)
                {
                    //Okay so this means it exists, let's instantiate it..
                    display = new BankDisplay();
                    display.Bank = (Bank)initializatonWindow.Instance;
                    
                }
                else
                {
                    display = new BankDisplay();
                    
                }
                
                Application.Run(display);
            }
            else if (profileBox.Profile == "Merchant") 
            {
                MerchantDisplay display;
                Initialization initializatonWindow = new Initialization();
                initializatonWindow.ShowDialog();
                initializatonWindow.NewName(false);
                if (initializatonWindow.Instance != null)
                {
                    //Okay so this means it exists, let's instantiate it..
                    display = new MerchantDisplay();
                    display.Merchant = (Merchant)initializatonWindow.Instance;
                }
                else
                {
                    Initialization initial = new Initialization();
                    initial.NewName(true);
                    initial.ShowDialog();
                    display = new MerchantDisplay();
                    display.Merchant.Name = initial.InstanceName;
                    display.Text = initial.InstanceName;
                }

                Application.Run(display);
            }


        }
    }
}